<?php
/**
*
* 版权所有：恰维网络<qwadmin.qiawei.com>
* 作    者：寒川<hanchuan@qiawei.com>
* 日    期：2016-01-21
* 版    本：1.0.0
* 功能说明：前台控制器演示。
*
**/
namespace Home\Controller;
use Think\Controller;
use Think\Verify;
use Vendor\Page;

class IndexController extends ComController {
    public function index(){

        $DorInfo=M("dorinfo");
        $ret1=$DorInfo->select();
        $Regtype=M("regtype");
        $ret2=$Regtype->select();
        $this->assign('ret1', $ret1)->assign('ret2', $ret2);
        $this->display();
    }
    public function chax(){
        $this->display();
    }
    
    public function cx(){
        $stuid=I("post.stuid",0);
        $phonum=I("post.phonum",0);
        if(!($stuid==0 && $phonum==0)){
            $Register=M("register");
            $ret=$Register->where("stuid=$stuid and phonum=$phonum")->order("regtime desc")->select();
            $this->assign('ret', $ret);
            $this->display();
        }

    }

    public function verify()
    {
        $config = array(
            'length' => 4, // 验证码位数
            'fontSize' => 40,
            'useCurve' => false,
            'reset' => false, // 验证成功后是否重置
        );
        $Verify = new Verify($config);
        $Verify->entry();
    }

    public function addTable()
    {
        if (IS_POST) {
            if($this->cv(I("post.verify"), "")){
                $data['name'] = I("post.name");
                $data['stuid'] = I("post.stuid");
                $data['phonum'] = I("post.phone");
                $data['dorid'] = I("post.dorid");
                $data['dornum'] = I("post.dornum");
                $data['typeid'] = I("post.typeid");
                $data['matdes'] = I("post.matdes");
                $data['jobpro'] = 0;
                $data['regtime'] = time();
                $Register=M("register");
                $ret=$Register->data($data)->add();
                if($ret){
                    $this->success('报修成功',U("Home/Index/index"),2);
                }else{
                    $this->error('报修失败',U("Home/Index/index"),3);
                }
            }else{
                $this->error('验证码错误',U("Home/Index/index"),3);
            }
        }
    }

    // 检测输入的验证码是否正确，$code为用户输入的验证码字符串
    function check_verify()
    {
        $code = I("post.verify");
        $this->ajaxReturn($this->cv($code));
    }

    public function cv($code){
        $id = '';
        $verify = new Verify();
        return $verify->check($code, $id);
    }

    public function Rcase(){
        $stuid=I("post.stuid");
        $phone=I("phone");
        if (!empty($stuid) and !empty($phone)){
            $Register=M("register");
            $where["stuid"]=$stuid;
            $where["phonum"]=$phone;
            $ret=$Register->where($where)->order("regtime")->select();
            $this->ajaxReturn($ret);
        }
    }
}